package com.oig.sys.file.api;

import com.oig.sys.file.api.factory.FileUploadFallBackFactory;
import com.oig.sys.file.vo.UploadVo;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

@FeignClient(contextId = "fileUploadService", value = "sys-file-server", path = "/file", fallbackFactory = FileUploadFallBackFactory.class)
public interface FileUploadService {

    /**
     * 单个文件上传
     */
    @PostMapping(value = "/upload", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    UploadVo upload(@RequestPart(name = "file") MultipartFile file);

    /**
     * 单个文件下载
     */
    @GetMapping("/download")
    ResponseEntity<byte[]> download(@RequestParam(name = "fileId") String fileId);


    @PostMapping("/moveBucket")
//    @Operation(summary = "文件从临时桶挪到配置的目标桶")
//    @Parameters({
//            @Parameter(name = "fileId", description = "文件的id"),
//            @Parameter(name = "businessType", description = "业务类型"),
//            @Parameter(name = "relationType", description = "关联单据类型")
//    })
    String moveBucket(@RequestParam(name ="fileId") String fileId,
                      @RequestParam(name ="businessType") String businessType,
                      @RequestParam(name ="relationType") String relationType);


    @PostMapping("/removeFile")
//    @Operation(summary = "文件删除文件")
//    @Parameter(name = "fileId", description = "文件的id")
    void removeFile(@RequestParam(name ="fileId") String fileId);


    @PostMapping("/getDownloadUrl")
//    @Operation(summary = "获取下载连接")
//    @Parameter(name = "fileId", description = "文件的id")
    String getDownloadUrl(@RequestParam(name ="fileId") String fileId);
}
